package com.zh.tea.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.ibatis.session.SqlSession;

import com.zh.tea.entity.Brand;
import com.zh.tea.entity.Type;
import com.zh.tea.service.BrandService;
import com.zh.tea.service.TypeService;
import com.zh.tea.service.impl.BrandServiceImpl;
import com.zh.tea.service.impl.TypeServiceImpl;

/**
 * Servlet implementation class TypeServlet
 */
@WebServlet("/TypeServlet")
public class TypeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TypeServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html; charset=utf-8");
		PrintWriter out=response.getWriter();
		HttpSession session=request.getSession();
		TypeService types=new TypeServiceImpl();
		List<Type> typelist=types.selectAllType();
		BrandService brands=new BrandServiceImpl();
		List<Brand> brandlist=brands.selectAllType();
		/*request.setAttribute("typelist", typelist);
		request.setAttribute("brandlist", brandlist);*/
		session.setAttribute("typelist", typelist);
		session.setAttribute("brandlist", brandlist);
		
		String opt=request.getParameter("opt");
		if("gettype".equals(opt)){
			response.sendRedirect("showtealists.jsp");
		}else{
		response.sendRedirect("/tea/admin/GoodsInsert.jsp");
		/*request.getRequestDispatcher("/admin/GoodsInsert.jsp").forward(request, response);*/
		}
		
		
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
